function handles=plot2DiffSamples(sampleOne,xOne,sampleTwo,xTwo,...
    str1,str2,flag_2y,legfont,widthvec,yoffset,xoffset,flag_color)
%function
%hand=plot2samp(sample,xmat,str1,str2,flag_2y,legfont,widthvec,yoffset,xoffset,flag_color)
% PLOT 2 SAMP 
% Input 
% Sample vector     [T 1]
% XMAT              [T 2] matrix of series 
% STR1              Name of first series legend 
% STR2              Name of second series legend
flag_doubley=0; lfsize=7; 
if isempty(str1)==true; 
 str1='Series 1'; 
end 
if isempty(str2)==true; 
 str2='Series 1'; 
end 
% =========================================================================
%% Double Axis? 
if nargin > 6
        if ~isempty(flag_2y) && flag_2y==1 
            flag_doubley=1; 
        end 
        if ~isempty(legfont); 
            lfsize=legfont; 
        end 
end 
%% Width of Lines 
if nargin < 9 || isempty(widthvec); 
    widthvec=[2.5 2]; 
else 
    if length(widthvec(:))~=2 
        error('WIDTHVEC must be 2x1') 
    end 
end 
if nargin < 10 || isempty(yoffset); 
    yoffset=0; 
end 
if nargin < 11 || isempty(xoffset); 
xoffset=0; 
end 
if nargin < 12 || isempty(flag_color); 
    flag_color=1; 
end 
% ========================================================================
%% Pad with NAN    
sampleVec=unique([sampleOne(:);sampleTwo(:)]);
NT   =length(sampleVec);
xmat  =nan(NT,2);
extractOne=( find( sampleVec==sampleOne(1) ) ):...
    ( find( sampleVec==sampleOne(end) ) );
extractTwo=( find( sampleVec==sampleTwo(1) ) ):...
    ( find( sampleVec==sampleTwo(end) ) );
xmat(extractOne,1)=xOne;
xmat(extractTwo,2)=xTwo;

if ~flag_doubley                                
    hand1=plot(sampleVec,xmat(:,1),'LineWidth',widthvec(1));hold on;
    hand2=plot(sampleVec,xmat(:,2),'--*','LineWidth',widthvec(2));    
    if flag_color==1
        set(hand1,'Color','b')
        set(hand2,'Color','r','MarkerSize',3);  hold off;
    else
        veclight=[0.7 0.7 0.7];
        set(hand1,'Color',veclight,'LineWidth',widthvec(1));
        set(hand2,'Color',[0.0 0.0 0.0],'LineStyle','--','MarkerSize',1,'LineWidth',widthvec(2));
    end        
    ymin=min(min(xmat)); 
    ymax=max(max(xmat)); 
    
    ylim([ymin-yoffset ymax+yoffset]); 
    
    xlim([sampleVec(1) sampleVec(end)+xoffset]); 
    
else  
    lineColors={'b','r'}; 
    [handaxis,hand1,hand2]=plotyy(sampleVec,xmat(:,1),sampleVec,xmat(:,2)); 
    set(hand1,'LineWidth',widthvec(1),'LineStyle','-'); 
    set(hand1,'Color',lineColors{1});
    set(handaxis(1),'YColor',lineColors{1},'FontSize',11); 
    set(hand2,'LineWidth',widthvec(2),'LineStyle','--');
    set(hand2,'Color',lineColors{2});
    set(handaxis(2),'YColor',lineColors{2},'FontSize',11);
end 
%if flag_nolegend==0
hh=legend(str1,str2,'Location','Best');
set(hh,'EdgeColor','w');
set(hh,'FontSize',lfsize);
set(hh,'Box','Off');
%end

handles.fig=gcf;     
handles.axis=handaxis; 
handles.line1=hand1; 
handles.line2=hand2; 

